package fr.labri.macchiato.core.model;


/**
 * An offer for a model, provided by a business entity and with a price
 * 
 * @author Matthieu FOUCAULT
 */
public class Offer extends AbstractProduct implements Product {

	Offer() {
		super();
	}

	private double price;
	private Article model;
	private BusinessEntity provider;

	public Offer(Article model, BusinessEntity provider, double price) {
		this();
		setModel(model);
		setProvider(provider);
		setPrice(price);
	}

	/**
	 * An offer equals another if their EAN-13 and provider are identical
	 */
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Offer)
			return ((Offer) obj).getEan().equals(this.getEan())
					&& ((Offer) obj).getProvider().equals(this.getProvider());
		else
			return false;
	}

	@Override
	public String getName() {
		return model.getName();
	}

	/**
	 * 
	 * @return the offer's price
	 */
	public double getPrice() {
		return price;
	}

	/**
	 * @return the offer's EAN
	 */
	public String getEan() {
		return model.getEan();
	}

	/**
	 * 
	 * @return the offer's {@link BusinessEntity}
	 */
	public BusinessEntity getProvider() {
		return provider;
	}

	/**
	 * 
	 * @return the offer's {@link Article}
	 */
	public Article getModel() {
		return model;
	}

	/**
	 * Sets the offer's model
	 * 
	 * @param model
	 */
	public void setModel(Article model) {
		this.model = model;

		notifyObservers();
	}

	/**
	 * Sets the offer price, price cannot be negative
	 * 
	 * @param price
	 */
	public void setPrice(double price) {
		this.price = price;

		notifyObservers();
	}

	/**
	 * Sets the offer provider
	 * 
	 * @param provider
	 */
	public void setProvider(BusinessEntity provider) {
		this.provider = provider;

		notifyObservers();
	}

	@Override
	public void setName(String name) {
		model.setName(name);
	}

}
